<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <button @click="showStore">显示仓库内容</button>
        <h1>{{this.$store.state.counter}}</h1>
        <button @click="add">加一</button>
    </div>

    <script src="./node_modules/vue/dist/vue.js"></script>
    <!-- 1引入vuex的依赖 -->
    <script src="./node_modules/vuex/dist/vuex.js"></script>
    <script src="./node_modules/axios/dist/axios.js"></script>

    <script>

        let store =new Vuex.Store({

               state:{
                   counter:888
               },
    
               mutations:{
                 increment:function(state,count){
                   state.counter += count ;
                 }
               },
               //提交异步操作
               actions:{
                   asyncIncrement:function(store){
            axios.get("http://linweiqin.cn:8001/statis/admin/2020-10-17/count").then(res=>{console.log(res.data.count);
                store.commit("increment",res.data.count)
            }).catch(err=>console.log(err))
                   }
               }
               
            
        })
  
        let vm =new Vue({

            store,
            el:"#app",
            data:{
               
            },
            methods:{
                showStore:function(){
                    console.log(this.$store);
                },
                add:function(){
                    this.$store.dispatch("asyncIncrement");
                }
            }
        })
    </script>
    
</body>
</html>